package com.kongcheng.nacosconsumer.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class TestController {

    @Autowired
    private RestTemplate restTemplate;

    /**
     * 注解开启ribbon负载均衡能力
     * @return
     */
    @Bean
    @LoadBalanced
    public RestTemplate getRestTemplate(){
        return new RestTemplate();
    }

    /**
     * RestTemplate+Ribbon进行服务调用
     * @return
     */
    @GetMapping("/consumer")
    public String test1(){
        return restTemplate.getForObject("http://nacos-provide/helloNacos",String.class);
    }
}
